package cn.agiledata.bank.common.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.dom4j.Document;
import org.dom4j.io.DOMReader;
import org.xml.sax.SAXException;

/**
 * 
 * @author 马贤波
 * 
 */
public class XmlUtil {
    private XmlUtil() {
    }

    /**
     * 根据xml内容创建表示该xml文件的org.dom4j.Document对象
     * 
     * @param xml
     *            xml内容
     * @return 表示xml文件的org.dom4j.Document对象
     * @throws SAXException
     * @throws IOException
     * @throws ParserConfigurationException
     */
    public static Document createDocument(String xml) throws SAXException,
            IOException, ParserConfigurationException {
        InputStream in = new ByteArrayInputStream(xml.getBytes());
        DocumentBuilder builder = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder();
        DOMReader reader = new DOMReader();
        return reader.read(builder.parse(in));
    }
}
